<template>
	<view style="padding-bottom: 40px;" class="text-df">
		<view class="margin radius-lg bg-white padding text-df">
			<view class="text-lg text-black text-bold text-center">
				{{data.title}}
			</view>

			<view class="text-center text-gray margin-top">
				发布时间：{{data.createTime}}
			</view>
			<view class="text-center text-gray margin-bottom" v-if="data.source">
				来源：{{data.source}}
			</view>

			<view class="rich-box">
				<rich-text :nodes="data.content" />
			</view>

		</view>
<!-- 		<view class="flex align-center justify-between bg-white padding"
			style="position: fixed;bottom: 0;width: 100%;left: 0;">
			<view class="">
				阅读数{{data.viewCount||0}}
			</view>
			<view class="">
				点赞数{{data.likeCount||0}}
			</view>
		</view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				PageLoad: false,
				PageData: {},
				data: {},
				id: ''
			}
		},
		onLoad(option) {
			this.id = option.id
			this.fethData()
		},
		onPullDownRefresh() {
			this.fethData(true);
		},
		methods: {
			fethData(isPull = false) {
				console.log(123)
				this.$http.get('/cadre/agricultural/' + this.id).then((res) => {
					this.data = res.data
					// #ifdef MP-WEIXIN
					let html = res.data.content
					html = html.replace('/api', this.$hd.baseUrl)
					let st = 'width:100%;height:auto;margin:0 auto;display:block'
					let graceRichTextReg = new RegExp('<' + 'img' + '>|<' + 'img' + ' (.\*?)>', 'gi')
					html = html.replace(graceRichTextReg, function(word) {
						if (word.indexOf('style=') != -1) {
							var regIn = new RegExp('<' + 'img' + '(.*?)style="(.*?)"(.*?)(/?)>',
								'gi');
							return word.replace(regIn, '<' + 'img' + '$1style="$2 ' + st +
								'"$3$4>');
						} else {
							var regIn = new RegExp('<' + 'img' + '(.*?)(/?)>', 'gi');
							return word.replace(regIn, '<' + 'img' + '$1 style="' + st +
								'$2">');
						}
					});

					this.data.content = html
					// #endif
					this.PageLoad = true;
					if (isPull) uni.stopPullDownRefresh();
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.rich-box img {
		width: 100% !important;
	}
</style>